<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<style type="text/css">
			#div1{
			    width: 300px;
				margin: auto;
			}
		</style>
	</head>
	<body>
		<div id="div1">
			<table border="0px" cellspacing="" cellpadding="" style="width: 250px ; height: 250px;">
				<tr>
					<td align="center">
						<select name="" id="sizes">
							<option value ="0">请下注</option>
							<option value="2">大</option>
							<option value="1">小</option>
						</select>
					</td>
				</tr>
				<tr>
					<td align="center">
						<img src="img/色子/1.jpg" id="imgs" >
					</td>
				</tr>
				<tr>
					<td align="center">
					    <button type="button" onclick="start(event)">开始</button>
					</td>
				</tr>
			</table>
		</div>
	</body>
	<script type="text/javascript">
	    function randomNumber(){
			while(true){
				var randomNum=Math.floor(Math.random()*10);
				if(randomNum>0 && randomNum<7){
					return randomNum ;
				}
			}
		}
		function start(event){
			var sizesObject = document.getElementById('sizes').value;
			if(sizesObject==0){
				alert('请下注')
			}else{
				event.target.innerText='选择中...';
				var sum=1;
				var num=1;
				var sta = setInterval(function(){
					num=randomNumber();
					console.log(num);
					var imgObject = document.getElementById('imgs');
					imgObject.src='img/色子/'+num+'.jpg';
					console.log('sizesObject:'+sizesObject,'num:'+num)
					if(sum==4){
						clearInterval(sta);
						event.target.innerText='开始';
						if(sizesObject==2 && num==4 || sizesObject==2 && num==5 ||sizesObject==2 && num==6 ||sizesObject==1 && num==3||sizesObject==1 && num==2||sizesObject==1 && num==1){
							alert('猜对了');
						}
						else{
							alert('猜错了');
						}
					}
					sum=sum+1;
				},1000)
			}
		}
	</script>
</html>
